﻿using UnityEngine;
using System.Collections;

/// <summary>
/// -Very fast (minutes) script to handle main menu buttons, attach to camera.  
/// Buttons are Sprites with colliders, action based on name of button.
/// </summary>

public class UI : MonoBehaviour {

    GameObject Highlight = null, Selected = null;
    // Update is called once per frame
    void Update() {

        if( Selected == null ) {
            Vector2 mPos = camera.ScreenToWorldPoint(Input.mousePosition);
            var hit = Physics2D.Raycast(mPos, Vector2.zero, 0.0f);

            GameObject hl = null;
            if(hit.collider != null) {
                hl = hit.collider.gameObject;
            }
            if(hl != Highlight) {
                if(hl) {
                    hl.GetComponent<SpriteRenderer>().color = Color.green;
                    // hl.transform.localScale = Vector3.one * 1.1f;
                }
                if(Highlight) {
                    Highlight.GetComponent<SpriteRenderer>().color = Color.white;
                    // Highlight.transform.localScale = Vector3.one;
                }
                Highlight = hl;
            }

            if( Highlight != null && Input.GetMouseButtonDown(0 )  ) {
                Highlight.GetComponent<SpriteRenderer>().color = Color.cyan;
                Selected = Highlight;
               
            }
        }
        if(Selected && !Input.GetMouseButton(0)) {
            if(Selected.name == "ExitB") { //lazy
                Application.Quit();

            } else
                Application.LoadLevel(1);
        }

    }


}
